home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Burning & Media / GB-PVR 1.2.13 / GBPVR10213.msi / Cabs.w1.cab / Search2.aspx.cs491 < prev    next >
Text File  |  2008-05-06  |  18KB  |  435 lines

  1. using System;
  2. using System.Collections;
  3. using System.Net;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.HtmlControls;
  7. using System.Web.UI.WebControls;
  8. using GBPVR.Public;
  9. using GBPVRSchedule;
  10. using gbweb.classes;
  11.  
  12. namespace gbweb
  13. {
  14.     /// <summary>
  15.     /// Summary description for Search.
  16.     /// </summary>
  17.     public partial class Search2 : Page
  18.     {
  19.         protected HtmlInputImage imageSubmit;
  20.         protected HtmlTableRow trMoviesOnly;
  21.         private Settings guideParams;
  22.         private static string showSearchResults;
  23.         private static int TimelineRepeat;
  24.  
  25.         protected void Page_Load(object sender, EventArgs e)
  26.         {
  27.             guideParams = Global.Settings;
  28.  
  29.             //Code to prevent Guest users from accessing the Search page directly by URL
  30.             if (!Convert.ToBoolean((string)Session["NotGuestUser"]))
  31.             {
  32.                 string hostAddress = string.Empty;
  33.                 string Url =
  34.                     Request.Url.ToString().Replace(Request.Url.Scheme + Uri.SchemeDelimiter + Request.Url.Authority,
  35.                                                    Request.Url.Scheme + Uri.SchemeDelimiter + Request.Headers["Host"]);
  36.  
  37.  
  38.                 string redirectUrl = Url.ToLower().Replace("search.aspx", "guide.aspx");
  39.                 Logger.Info(" ");
  40.                 Logger.Info(" ");
  41.                 Logger.Info("Guest user trying to access the search page......");
  42.                 Logger.Info("Pulling User IP Info...");
  43.                 if (Request.UserHostAddress.Substring(0, 1) == ":")
  44.                 {
  45.                     Logger.Info("IP V6 Detected");
  46.                     hostAddress = GetIP4Address();
  47.                     Logger.Info("IP6 Address: " + Request.UserHostAddress);
  48.                     Logger.Info("IP4 Address: " + hostAddress);
  49.                     Logger.Info(" ");
  50.                 }
  51.                 else
  52.                 {
  53.                     Logger.Info("IP V4 Detected");
  54.                     hostAddress = Request.UserHostAddress;
  55.                     Logger.Info("IP4 Address: " + hostAddress);
  56.                     Logger.Info(" ");
  57.                 }
  58.                 Logger.Info("Redirecting user to the guide");
  59.                 Logger.Info(" ");
  60.                 Logger.Info(" ");
  61.                 Response.Redirect(redirectUrl, true);
  62.             }
  63.             
  64.             Session["GuideStartTime"] = null;
  65.             if (!IsPostBack)
  66.             {
  67.                 //Set the Day/date/time display on the header
  68.                 viewDate.InnerText = DateTime.Now.ToLongDateString().Trim();
  69.                 serverTime.InnerText = "Server Time: " + DateTime.Now.ToLongTimeString().Trim();
  70.  
  71.                 //Set the header tab of the Search to active
  72.                 NAV_SEARCH.Attributes.Add("class", "currentTab");
  73.                 NAV_RECORDINGS.Visible = guideParams.showManage;
  74.                 NAV_SEARCH.Visible = guideParams.showSearch;
  75.                 NAV_VIDEO.Visible = guideParams.showVideoLib;
  76.                 NAV_MUSIC.Visible = guideParams.showMusicLib;
  77.                 NAV_PHOTO.Visible = guideParams.showPhotoLib;
  78.                 NAV_STATS.Visible = guideParams.showStats;
  79.  
  80.                 SavedSearchUtils searchUtil = new SavedSearchUtils();
  81.                 searchUtil.loadSearchList(savedSearchList, savedSearchFilter.SelectedValue);
  82.                 HttpCookie cookie = Request.Cookies["showSearchResults"];
  83.                 showSearchResults = cookie != null ? cookie.Value : "tree";
  84.  
  85.                 Schedule scheduleHelper = Global.Schedule;
  86.                 IList listingsForPeriod;
  87.                 listingsForPeriod = scheduleHelper.GetListingsForTimePeriod(DateTime.Now, DateTime.Now);
  88.  
  89.                 foreach (Channel channel in listingsForPeriod)
  90.                 {
  91.                     listChannels.Items.Add(new ListItem(channel.getName(), channel.channelNumber.ToString()));
  92.                 }
  93.  
  94.                 Global.FillGenreList(genreList);
  95.  
  96.                 //Clear out Session variables that hold the search criteria
  97.                 Session["checkTitle"] = null;
  98.                 Session["checkDescription"] = null;
  99.                 Session["checkSubtitle"] = null;
  100.                 Session["matchTitle"] = null;
  101.                 Session["matchDesc"] = null;
  102.                 Session["matchSubtitle"] = null;
  103.                 Session["matchUniqueID"] = null;
  104.                 Session["textKeyWord"] = null;
  105.                 Session["caseSensitive"] = null;
  106.                 Session["minLength"] = null;
  107.                 Session["maxLength"] = null;
  108.                 Session["channels"] = null;
  109.                 Session["genreList"] = null;
  110.                 Session["startDate"] = null;
  111.                 Session["startTime"] = null;
  112.                 Session["endDate"] = null;
  113.                 Session["endTime"] = null;
  114.             }
  115.         }
  116.  
  117.         #region Web Form Designer generated code
  118.         override protected void OnInit(EventArgs e)
  119.         {
  120.             //
  121.             // CODEGEN: This call is required by the ASP.NET Web Form Designer.
  122.             //
  123.             InitializeComponent();
  124.             base.OnInit(e);
  125.         }
  126.  
  127.         /// <summary>
  128.         /// Required method for Designer support - do not modify
  129.         /// the contents of this method with the code editor.
  130.         /// </summary>
  131.         private void InitializeComponent()
  132.         {
  133.  
  134.         }
  135.  
  136.         #endregion
  137.  
  138.         protected void hlSubmit_Click(object sender, EventArgs e)
  139.         {
  140.             if ((searchPhrase.Value.Length > 0) ||
  141.                 ((searchPhrase.Value.Length == 0) &&
  142.                 ((genreList.SelectedValue != null && genreList.SelectedValue != "") ||
  143.                  (startDate.PostedDate != null && startDate.PostedDate != "") ||
  144.                  (startTime.PostedTime != null && startTime.PostedTime != "") ||
  145.                  (endDate.PostedDate != null && endDate.PostedDate != "") ||
  146.                  (endTime.PostedTime != null && endTime.PostedTime != "") ||
  147.                  (textMinLength.Value != null && textMinLength.Value != "") ||
  148.                  (textMaxLength.Value != null && textMaxLength.Value != "") ||
  149.                  (listChannels.SelectedValue != null && listChannels.SelectedValue != ""))))
  150.             {
  151.                 //Transfer user to Search Results page for viewing
  152.                 Server.Transfer("SearchResults2.aspx");
  153.             }
  154.         }
  155.  
  156.         protected void hlReset_Click(object sender, EventArgs e)
  157.         {
  158.             //Back to search page to reset values
  159.             Response.Redirect("Search2.aspx");
  160.         }
  161.         
  162.         protected void loadSearch(object sender, EventArgs e)
  163.         {
  164.            
  165.             if (savedSearchList.SelectedIndex != 0)
  166.             {
  167.                 SavedSearchUtils searchUtils = new SavedSearchUtils();
  168.                 SavedSearch search = searchUtils.loadSearch(savedSearchList.SelectedValue);
  169.                 autoSearchInclude.Checked = search.isAutoShowSearch();
  170.                 autoRecordInclude.Checked = search.isAutoRecordSearch();
  171.                 checkTitle.Checked = search.getSearchTitle();
  172.                 checkDescription.Checked = search.getSearchDescription();
  173.                 checkSubTitle.Checked = search.getSearchSubTitle();
  174.                 searchPhrase.Value = search.getSearchPhrase();
  175.                 caseSensitive.Checked = search.isCaseSensitiveSearch();
  176.                 textMinLength.Value = search.getSearchLengthMin();
  177.                 textMaxLength.Value = search.getSearchLengthMax();
  178.  
  179.                 if (search.getSearchStartDate() != null && search.getSearchStartDate() != "" && search.getSearchStartDate() != "1/1/0001")
  180.                 {
  181.                     startDate.SelectedDate = searchUtils.toDate(search.getSearchStartDate());
  182.                 }
  183.                 else
  184.                 {
  185.                     startDate.Clear();
  186.                 }
  187.                 if (search.getSearchStartTime() != null && search.getSearchStartTime() != "" && (search.getSearchStartTime() != "12:00 AM" && search.getSearchStartDate() != "1/1/0001"))
  188.                 {
  189.                     startTime.SelectedTime = searchUtils.toDate(search.getSearchStartTime());
  190.                 }
  191.                 else
  192.                 {
  193.                     startTime.Clear();
  194.                 }
  195.                 if (search.getSearchEndDate() != null && search.getSearchEndDate() != "" && search.getSearchEndDate() != "1/1/0001")
  196.                 {
  197.                     endDate.SelectedDate = searchUtils.toDate(search.getSearchEndDate());
  198.                 }
  199.                 else
  200.                 {
  201.                     endDate.Clear();
  202.                 }
  203.                 if (search.getSearchEndTime() != null && search.getSearchEndTime() != "" && (search.getSearchEndTime() != "12:00 AM" && search.getSearchEndDate() != "1/1/0001"))
  204.                 {
  205.                     endTime.SelectedTime = searchUtils.toDate(search.getSearchEndTime());
  206.                 }
  207.                 else
  208.                 {
  209.                     endTime.Clear();
  210.                 }
  211.  
  212.                 genreList.SelectedIndex = -1;
  213.                 listChannels.SelectedIndex = -1;
  214.                 
  215.                 foreach (string genre in search.getSearchGenres())
  216.                 {
  217.                     try
  218.                     {
  219.                         genreList.Items.FindByValue(genre).Selected = true;
  220.                     }
  221.                     catch
  222.                     {
  223.                     }
  224.                 }
  225.  
  226.                 foreach (string channel in search.getSearchChannels())
  227.                 {
  228.                     try
  229.                     {
  230.                         listChannels.Items.FindByValue(channel).Selected = true;
  231.                     }
  232.                     catch
  233.                     {
  234.                     }
  235.                 }
  236.                 //If our saved search does not match the current search version value then we need to update it so that it has all the new default values
  237.                 guideParams = Global.Settings;
  238.                 if (search.getSearchVersion() != guideParams.CurrentSearchVersion)
  239.                 {
  240.                     updateSavedSearch_Click(null, null);
  241.                 }
  242.             }
  243.             else
  244.             {
  245.                 newSearchName.Value = "";
  246.                 searchPhrase.Value = "";
  247.                 foreach (ListItem item in genreList.Items)
  248.                 {
  249.                     item.Selected = false;
  250.                 }
  251.                 foreach (ListItem item in listChannels.Items)
  252.                 {
  253.                     item.Selected = false;
  254.                 }
  255.             }
  256.         }
  257.  
  258.         protected void deleteSavedSearch_Click(object sender, EventArgs e)
  259.         {
  260.             if (savedSearchList.SelectedIndex != 0)
  261.             {
  262.                 SavedSearchUtils searchUtil = new SavedSearchUtils();
  263.                 searchUtil.deleteSearch(savedSearchList.SelectedValue);
  264.                 savedSearchList.Items.Clear();
  265.                 searchUtil.loadSearchList(savedSearchList, savedSearchFilter.SelectedValue);
  266.                 savedSearchList.SelectedIndex = 0;
  267.  
  268.                 newSearchName.Value = "";
  269.                 searchPhrase.Value = "";
  270.                 foreach (ListItem item in genreList.Items)
  271.                 {
  272.                     item.Selected = false;
  273.                 }
  274.                 foreach (ListItem item in listChannels.Items)
  275.                 {
  276.                     item.Selected = false;
  277.                 }
  278.  
  279.             }
  280.         }
  281.  
  282.         protected void saveSearch_Click(object sender, EventArgs e)
  283.         {
  284.  
  285.             if (newSearchName.Value.Length > 0)
  286.             {
  287.                 SavedSearch search = new SavedSearch();
  288.                 search.setSearchName(newSearchName.Value);
  289.                 search.setautoShowSearch(autoSearchInclude.Checked);
  290.                 search.setautoRecordSearch(autoRecordInclude.Checked);
  291.                 search.setSearchTitle(checkTitle.Checked);
  292.                 search.setSearchSubTitle(checkSubTitle.Checked);
  293.                 search.setSearchDescription(checkDescription.Checked);
  294.                 search.setSearchPhrase(searchPhrase.Value);
  295.                 search.setSearchCaseSensitive(caseSensitive.Checked);
  296.                 foreach(ListItem item in genreList.Items)
  297.                 {
  298.                     if (item.Selected)
  299.                     {
  300.                         search.addSearchGenres(item.Value);
  301.                     }
  302.                 }
  303.                 search.setSearchLengthMin(textMinLength.Value);
  304.                 search.setSearchLengthMax(textMaxLength.Value);
  305.                 foreach (ListItem item in listChannels.Items)
  306.                 {
  307.                     if (item.Selected)
  308.                     {
  309.                         search.addSearchChannels(item.Value);
  310.                     }
  311.                 }
  312.  
  313.                 if (searchPhrase.Value.Length == 0 && genreList.SelectedIndex == -1 && listChannels.SelectedIndex == -1 &&
  314.                     textMaxLength.Value.Length == 0 && textMinLength.Value.Length == 0)
  315.                 {
  316.                     search.setSearchPhrase(newSearchName.Value);
  317.                     searchPhrase.Value = newSearchName.Value;
  318.                 }
  319.  
  320.                 if (startDate.PostedDate != "")
  321.                 {
  322.                     search.setSearchStartDate(startDate.PostedDate);
  323.                 }
  324.                 else
  325.                 {
  326.                     search.setSearchStartDate(null);
  327.                 }
  328.                 search.setSearchStartTime(startTime.PostedTime);
  329.  
  330.                 if (endDate.PostedDate != "")
  331.                 {
  332.                     search.setSearchEndDate(endDate.PostedDate);
  333.                 }
  334.                 else
  335.                 {
  336.                     search.setSearchEndDate(null);
  337.                 }
  338.                 search.setSearchEndTime(endTime.PostedTime);
  339.  
  340.                 SavedSearchUtils searchUtil = new SavedSearchUtils();
  341.                 searchUtil.deleteSearch(newSearchName.Value);
  342.                 searchUtil.writeSearch(search);
  343.                 savedSearchList.Items.Clear();
  344.                 searchUtil.loadSearchList(savedSearchList, savedSearchFilter.SelectedValue);
  345.                 savedSearchList.SelectedValue = newSearchName.Value;
  346.                 newSearchName.Value = string.Empty;
  347.             }
  348.         }
  349.  
  350.         protected void updateSavedSearch_Click(object sender, EventArgs e)
  351.         {
  352.             SavedSearch search = new SavedSearch();
  353.             guideParams = Global.Settings;
  354.             search.setSearchName(savedSearchList.SelectedValue);
  355.             search.setSearchVersion(guideParams.CurrentSearchVersion);
  356.             search.setautoShowSearch(autoSearchInclude.Checked);
  357.             search.setautoRecordSearch(autoRecordInclude.Checked);
  358.             search.setSearchTitle(checkTitle.Checked);
  359.             search.setSearchSubTitle(checkSubTitle.Checked);
  360.             search.setSearchDescription(checkDescription.Checked);
  361.             search.setSearchPhrase(searchPhrase.Value);
  362.             search.setSearchCaseSensitive(caseSensitive.Checked);
  363.             foreach (ListItem item in genreList.Items)
  364.             {
  365.                 if (item.Selected)
  366.                 {
  367.                     search.addSearchGenres(item.Value);
  368.                 }
  369.             }
  370.             search.setSearchLengthMin(textMinLength.Value);
  371.             search.setSearchLengthMax(textMaxLength.Value);
  372.             foreach (ListItem item in listChannels.Items)
  373.             {
  374.                 if (item.Selected)
  375.                 {
  376.                     search.addSearchChannels(item.Value);
  377.                 }
  378.             }
  379.  
  380.             if (searchPhrase.Value.Length == 0 && genreList.Items.Count == 0 && listChannels.Items.Count == 0 &&
  381.                 textMaxLength.Value.Length == 0 && textMinLength.Value.Length == 0)
  382.             {
  383.                 search.setSearchPhrase(newSearchName.Value);
  384.             }
  385.  
  386.             if (startDate.PostedDate != "")
  387.             {
  388.                 search.setSearchStartDate(startDate.PostedDate);
  389.             }
  390.             else
  391.             {
  392.                 search.setSearchStartDate(null);
  393.             }
  394.             search.setSearchStartTime(startTime.PostedTime);
  395.  
  396.             if (endDate.PostedDate != "")
  397.             {
  398.                 search.setSearchEndDate(endDate.PostedDate);
  399.             }
  400.             else
  401.             {
  402.                 search.setSearchEndDate(null);
  403.             }
  404.             search.setSearchEndTime(endTime.PostedTime);
  405.  
  406.             SavedSearchUtils searchUtil = new SavedSearchUtils();
  407.             searchUtil.deleteSearch(savedSearchList.SelectedValue);
  408.             searchUtil.writeSearch(search);
  409.          }
  410.       
  411.         protected void savedSearchFilter_SelectedIndexChanged(object sender, EventArgs e)
  412.         {
  413.             SavedSearchUtils searchUtil = new SavedSearchUtils();
  414.             savedSearchList.Items.Clear();
  415.             searchUtil.loadSearchList(savedSearchList, savedSearchFilter.SelectedValue);
  416.         }
  417.  
  418.         public string GetIP4Address()
  419.         {
  420.             string strIP4Address = String.Empty;
  421.  
  422.             foreach (IPAddress objIP in Dns.GetHostAddresses(Dns.GetHostName()))
  423.             {
  424.                 if (objIP.AddressFamily.ToString() == "InterNetwork")
  425.                 {
  426.                     strIP4Address = objIP.ToString();
  427.                     break;
  428.                 }
  429.             }
  430.             return strIP4Address;
  431.         }
  432.  
  433. }
  434.